package com.gz.furnitures.dao.impl;

import com.gz.furnitures.dao.BasicDao;
import com.gz.furnitures.dao.MemberDao;
import com.gz.furnitures.entity.Member;

public class MemberDaoImpl extends BasicDao<Member> implements MemberDao {

    @Override
    public Member queryMemberByName(String username) {
        String sql = "select * from member where username = ?";
        Member member = querySingle(sql, Member.class, username);
        return member;
    }

    @Override
    public Member queryMemberByNameAndPassword(String username, String password) {
        String sql = "select * from member where username = ? and password = MD5(?)";
        Member member = querySingle(sql, Member.class, username, password);
        return member;
    }


    /**
     * 保存一个会员
     * @param member
     * @return 返回-1就是失败，返回其他数字就是影响行数
     */
    @Override
    public int insertMember(Member member) {
        String sql = "insert into member (username,password,email) values(?,MD5(?),?)";
        return update(sql, member.getUsername(),
                member.getPassword(), member.getEmail());
    }
}
